package com.db;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;

import com.thread.MainWorker;

public class DBInfo {
	public static String dbname = DBCommon.dbname ;
	public static String dbuser = DBCommon.dbuser ;
	public static String dbpassword = DBCommon.dbpassword ;
	public static String dbur1 = DBCommon.dbur1;
	
	static Logger logger = Logger.getLogger(DBInfo.class);  
	
	
	public static boolean insertInfo(String Settingid, String pinglun, String zhuanfa, String shoucang, String dianji) {
		boolean rets = false;
		try {

			Connection conn = null;
			Statement sql = null;
			// set = null ;
			try {
				try {
					try {
						Class.forName("com.mysql.jdbc.Driver");
					} catch (ClassNotFoundException e) {
						System.out.println("" + e);
						logger.error(e+"") ;
					}
					try {
						SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss") ;
						String nowDate = sdf.format(new Date()) ;
//						String dbur1 = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=Sing.mdb";
//						String dbur1 = "jdbc:mysql://47.96.8.102:3306/"+dbname+"?characterEncoding=UTF-8&useSSL=false";
						conn = DriverManager.getConnection(dbur1, dbuser, dbpassword);
						sql = conn.createStatement();
						//String sqlstr = "SELECT ID,title,content,isImediate,publishTime,photos,fengmian,videopath,portalphotopath from publish_setting  ";
						String sqlstr = "insert into publish_info(Settingid,pinglun,zhuanfa,shoucang,dianji) values("+Settingid+","+pinglun+","+zhuanfa+","+shoucang+","+dianji+") ";
						System.out.println(sqlstr);
						logger.info(sqlstr) ;
						sql.execute(sqlstr);
						// System.out.println(set.next());
						rets = true;
						conn.close();
					} catch (Exception el) {
						el.printStackTrace();
						logger.error(el+"") ;
					} finally {
						if (sql != null) {
							sql.close();
						}
						if (conn != null) {
							conn.close();
						}
						conn = null;
					}

				} catch (Exception e) {
					e.printStackTrace();
					logger.error(e+"") ;
				} finally {
					if (sql != null) {
						sql.close();
					}
					// if(set!=null){
					//
					// }
					if (conn != null) {
						conn.close();
					}
				}
			} catch (Exception e) {
				System.out.println("" + e);
				logger.error(e+"") ;
			}

		} catch (Exception e) {
			e.printStackTrace();
		}
		return rets;
	}
	
	
	

	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
//		DB.queryCode("15");
		DBInfo.insertInfo("1", "1", "1", "1", "1");
	}

}
